 /**
  * Copyright (c) 2017-2019 tencent, All rights reseved.
  * @fileoverview abnormal
  * @author carllsun | carllsun@tencent.com
  * @version 1.0  | 2017-12-01 | carllsun    // 初始版本。
  *
  * ### abnormal
  * | 名称                  | 描述                         |
  * |----------------------|------------------------------|
  * |`type`                | [说明]：异常状态类型，其优先级低于其他属性。<br>[类型]：`String`<br>默认值：`""` <br>[可选值]：`REQUEST_ERROR, NOT_FOUND, DATA`|
  * |`image`               | [说明]：背景图。若与 `type` 同时指定，将覆盖 `type` 对应的 `image` 。<br>[类型]：`String`<br>[默认值]：`""` <br>   |
  * |`title`               | [说明]：标题。若与 `type` 同时指定，将覆盖 `type` 对应的 `title` 。<br>[类型]：`String`<br>[默认值]：`""` <br>     |
  * |`tip`                 | [说明]：副标题。若与 `type` 同时指定，将覆盖 `type` 对应的 `tip` 。<br>[类型]：`String`<br>[默认值]：`""` <br>       |
  * |`button`              | [说明]：按钮文案。若与 `type` 同时指定，将覆盖 `type` 对应的 `button` 。<br>[类型]：`String`<br>[默认值]：`""` <br>  |
  * |`bindabnortap`        | [说明]：按钮事件。若配置了 `button` 属性，则需要指定事件。其中 `REQUEST_ERROR, NOT_FOUND` 两种 `type` 中均设置了默认的按钮文案 | 
 */

// import Types from './config.js';

let Types = {
  'REQUEST_ERROR': {
    image: 'https://s10.mogucdn.com/p2/161213/upload_3bd517df2kgkclkhgl71bg4b37dcc_514x260.png',
    title: '网络加载失败',
    button: '点击刷新'
  },
  'NOT_FOUND': {
    image: 'https://s8.mogucdn.com/pic/150112/17y7h4_ieydcyjsha2dgndcmuytambqgiyde_410x354.png',
    title: '很抱歉，找不到你要访问的页面',
    button: '返回'
  },
  'DATA': {
    image: 'https://s10.mogucdn.com/p2/161213/upload_27e7gegi3f9acl5e05f3951if5855_514x260.png',
    title: '没有相关数据哦'
  }
};

Component({
  behaviors: [],
  properties: {
    type: {
      type: String,
      value: '',
      observer(type) {
        if (type && Types[type]) {
          let image = this.data.image || Types[type].image;
          let title = this.data.title || Types[type].title;
          let button = this.data.button || Types[type].button;
          let tip = this.data.tip || Types[type].tip;
          this.setData({
            image,
            title,
            button,
            tip
          })
        }
      }
    },
    image: {
      type: String,
      value: ''
    },
    title: {
      type: String,
      value: ''
    },
    tip: {
      type: String,
      value: ''
    },
    button: {
      type: String,
      value: ''
    }
  },
  data: {},
  methods: {
    emitAbnorTap(event) {
      let detail = event.detail;
      let option = {};
      this.triggerEvent('abnortap', detail, option);
    }
  }
})
